﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace FixedAssets.Controls.Check
{
    public partial class ShowCheck_Control : System.Web.UI.UserControl
    {
        TKFA.BLL.FA_CHECKPLAN bll = new TKFA.BLL.FA_CHECKPLAN();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadAll();
            }
            else
            {
                this.C1GridView1.DataKeyNames = new[] { "SCHECKPLANID" };
                //if (Request["__EVENTTARGET"].Contains(this.C1GridView1.ID))
                //{
                //    LoadGridView(Request["__EVENTARGUMENT"]);
                //}
            }
        }


        private void LoadAll()
        {
            this.C1GridView1.DataSource = AddIdToTable(bll.GetCheckPlanDT());
            this.C1GridView1.DataBind();
            this.C1GridView1.DataKeyNames = new[]{ "SCHECKPLANID"};
        }
        private DataTable AddIdToTable(DataTable dt)
        {
            DataTable idt = dt.Copy();
            idt.Columns.Add("ID", typeof(int));
            int rowid=1;
            foreach (DataRow dr in idt.Rows)
            {
                dr["ID"] = rowid;
                rowid++;
            }

            if (dt.PrimaryKey.Length > 0)
            {
                idt.PrimaryKey = dt.PrimaryKey;
            }
            return idt;

        }

        protected void C1GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
           string str_cpid= this.C1GridView1.Rows[this.C1GridView1.SelectedIndex].Cells[1].Text;
           DataTable dt= bll.GetCheckPlanValue(str_cpid);
           this.C1GridView2.DataSource = AddIdToTable(dt);
           this.C1GridView2.DataBind();
           this.C1GridView2.Visible = true;
           this.Div_View2.Visible = true;
        }


    }
}